﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using dal;
using entity;
using DAL;
using System.Data;
using cmsservice.BLL;

/// <summary>
///CommonBLL 的摘要说明
/// </summary>
public class CommonBLL
{
    private Dictionary<string, string> dicStocks;

    private List<TB_BK_GG> lstStockType = null;

    private Dictionary<string, TB_BK> dicType;

    private List<ConcernedStock> lstConcernedStock;
    /// <summary>
    ///  板块
    /// </summary>
    public Dictionary<string, TB_BK> DicType
    {
        get
        {
            if (dicType != null)
            {
                return dicType;
            }
            string key = "CommonBLL.DicType";
            dicType = (Dictionary<string, TB_BK>)System.Web.HttpContext.Current.Cache[key];
            if (dicType != null)
            {
                return dicType;
            }
            MainQuoteDBEntities db = new MainQuoteDBEntities();
            var lst = db.TB_BK.ToArray();
            dicType = new Dictionary<string, TB_BK>();
            foreach (var c in lst)
            {
                if (!dicType.Keys.Contains(c.BK_CODE))
                {
                    dicType.Add(c.BK_CODE, c);
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dicType, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dicType;
        }
    }

    public Dictionary<string, string> DicStock
    {
        get
        {
            if (dicStocks != null)
            {
                return dicStocks;
            }
            string key = "CommonBLL.DicStock";
            if (System.Web.HttpContext.Current != null)
            {
                dicStocks = (Dictionary<string, string>)System.Web.HttpContext.Current.Cache[key];
            }
            if (dicStocks != null)
            {
                return dicStocks;
            }
            SecurityBLL securityBLL = new SecurityBLL();
            var lst = securityBLL.GetAll();
            dicStocks = new Dictionary<string, string>(); 
            foreach (var c in lst)
            {
                if (!dicStocks.ContainsKey(c.SecuCode))
                {
                    dicStocks.Add(c.SecuCode, c.SecuAbbr);
                }
            }
            //System.Web.HttpContext.Current.Cache.Add(key, dicStocks, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);

            return dicStocks;
        }
        set
        {
            dicStocks = value;
        }
    }

    /// <summary>
    /// 板块代码和股票的关系
    /// </summary>
    public List<TB_BK_GG> LstStockType
    {
        get
        {

            if (lstStockType != null)
            {
                return lstStockType;
            }
            string key = "CommonBLL.DicStockType";
            lstStockType = (List<TB_BK_GG>)System.Web.HttpContext.Current.Cache[key];
            if (lstStockType != null)
            {
                return lstStockType;
            }
            MainQuoteDBEntities db = new MainQuoteDBEntities();
            lstStockType = db.TB_BK_GG.ToList();
            System.Web.HttpContext.Current.Cache.Add(key, lstStockType, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return lstStockType;
        }
    }

    private Dictionary<string, TB_BK> dic股票对应行业类型;

    public Dictionary<string, TB_BK> Dic股票对应行业类型
    {
        get
        {
            if (dic股票对应行业类型 != null)
            {
                return dic股票对应行业类型;
            }
            string key = "CommonBLL.股票对应行业类型";
            dic股票对应行业类型 = (Dictionary<string, TB_BK>)System.Web.HttpContext.Current.Cache[key];
            if (dic股票对应行业类型 != null)
            {
                return dic股票对应行业类型;
            }
            dic股票对应行业类型 = new Dictionary<string, TB_BK>();
            foreach (var c in LstStockType)
            {
                try
                {
                    if (c.BK_CODE.StartsWith("002"))
                    {
                        dic股票对应行业类型.Add(c.GG_CODE, DicType[c.BK_CODE]);
                    }
                }
                catch
                {
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic股票对应行业类型, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic股票对应行业类型;
        }
    }

    /// <summary>
    /// 板块关注的股票
    /// </summary>
    public List<ConcernedStock> LstConcernedStock
    {
        get
        {
            if (lstConcernedStock != null)
            {
                return lstConcernedStock;
            }
            string key = "CommonBLL.LstConcernedStock";
            lstConcernedStock = (List<ConcernedStock>)System.Web.HttpContext.Current.Cache[key];
            if (lstConcernedStock != null)
            {
                return lstConcernedStock;
            }
            ConcernedStockDAL dal = new ConcernedStockDAL();
            lstConcernedStock = dal.GetAllData();
            for (int i = 0; i < lstConcernedStock.Count; i++)
            {
                lstConcernedStock[i].BKID = lstConcernedStock[i].BKID.Replace("BK", "00");
            }
            System.Web.HttpContext.Current.Cache.Add(key, lstConcernedStock, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return lstConcernedStock;
        }
    }

    List<IndustryStatus> lstIndustryStatus;

    /// <summary>
    /// 行业现状
    /// </summary>
    public List<IndustryStatus> LstIndustryStatus
    {
        get
        {
            if (lstIndustryStatus != null)
            {
                return lstIndustryStatus;
            }
            string key = "CommonBLL.LstIndustryStatus";
            lstIndustryStatus = (List<IndustryStatus>)System.Web.HttpContext.Current.Cache[key];
            if (lstIndustryStatus != null)
            {
                return lstIndustryStatus;
            }
            QgqpDAL dal = new QgqpDAL();
            lstIndustryStatus = dal.GetAllIndustryStatus();
            for (int i = 0; i < lstIndustryStatus.Count; i++)
            {
                lstIndustryStatus[i].BKID = lstIndustryStatus[i].BKID.Replace("BK", "00");
            }
            System.Web.HttpContext.Current.Cache.Add(key, lstIndustryStatus, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return lstIndustryStatus;
        }
    }

    List<InvestmentHighlights> lstInvestmentHighlights;

    /// <summary>
    ///  投资要点
    /// </summary>
    public List<InvestmentHighlights> LstInvestmentHighlights
    {
        get
        {
            if (lstInvestmentHighlights != null)
            {
                return lstInvestmentHighlights;
            }
            string key = "CommonBLL.LstInvestmentHighlights";
            lstInvestmentHighlights = (List<InvestmentHighlights>)System.Web.HttpContext.Current.Cache[key];
            if (lstInvestmentHighlights != null)
            {
                return lstInvestmentHighlights;
            }
            QgqpDAL dal = new QgqpDAL();
            lstInvestmentHighlights = dal.GetAllInvestmentHighlights();
            for (int i = 0; i < lstInvestmentHighlights.Count; i++)
            {
                lstInvestmentHighlights[i].BKID = lstInvestmentHighlights[i].BKID.Replace("BK", "00");
            }
            System.Web.HttpContext.Current.Cache.Add(key, lstInvestmentHighlights, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return lstInvestmentHighlights;
        }
    }

    Dictionary<string, gaAnalysis> dicGaAnalysis;

    /// <summary>
    /// 投资评级统计
    /// </summary>
    public Dictionary<string, gaAnalysis> DicGaAnalysis
    {
        get
        {
            if (dicGaAnalysis != null)
            {
                return dicGaAnalysis;
            }
            string key = "CommonBLL.DicGaAnalysis";
            dicGaAnalysis = (Dictionary<string, gaAnalysis>)System.Web.HttpContext.Current.Cache[key];
            if (dicGaAnalysis != null)
            {
                return dicGaAnalysis;
            }
            WebsiteDataEntities dalW = new WebsiteDataEntities();
            List<gaAnalysis> lstGa = dalW.gaAnalysis.ToList();
            if (lstGa.Count > 0)
            {
                dicGaAnalysis = new Dictionary<string, gaAnalysis>();
                foreach (var ga in lstGa)
                {
                    try
                    {
                        dicGaAnalysis.Add(ga.StockCode, ga);
                    }
                    catch
                    {
                    }
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dicGaAnalysis, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dicGaAnalysis;
        }
    }

    Dictionary<string, entity.CompanyOverview> dicCompanyOverview; 

    /// <summary>
    /// 公司概况
    /// </summary>
    public Dictionary<string, entity.CompanyOverview> DicCompanyOverview
    {
        get
        {
            if (dicCompanyOverview != null)
            {
                return dicCompanyOverview;
            }
            string key = "CommonBLL.DicCompanyOverview";
            dicCompanyOverview = (Dictionary<string, entity.CompanyOverview>)System.Web.HttpContext.Current.Cache[key];
            if (dicCompanyOverview != null)
            {
                return dicCompanyOverview;
            }
            QgqpDAL dal = new QgqpDAL();
            List<entity.CompanyOverview> lstGa = dal.Get公司概况();
            if (lstGa.Count > 0)
            {
                dicCompanyOverview = new Dictionary<string, entity.CompanyOverview>();
                foreach (var ga in lstGa)
                {
                    try
                    {
                        dicCompanyOverview.Add(ga.StockId, ga);
                    }
                    catch
                    {
                    }
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dicCompanyOverview, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dicCompanyOverview;
        }
    }

    Dictionary<string, LaybareSecret> dicLaybareSecret;

    /// <summary>
    /// 道破天机
    /// </summary>
    public Dictionary<string, LaybareSecret> DicLaybareSecret
    {
        get
        {
            if (dicLaybareSecret != null)
            {
                return dicLaybareSecret;
            }
            string key = "CommonBLL.DicLaybareSecret";
            dicLaybareSecret = (Dictionary<string, LaybareSecret>)System.Web.HttpContext.Current.Cache[key];
            if (dicLaybareSecret != null)
            {
                return dicLaybareSecret;
            }
            QgqpDAL q = new QgqpDAL();
            var lst = q.GetDPTJ();
            dicLaybareSecret = new Dictionary<string, LaybareSecret>();
            foreach (var c in lst)
            {
                try
                {
                    dicLaybareSecret.Add(c.StockId, c);
                }
                catch
                {
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dicLaybareSecret, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dicLaybareSecret;
        }
    }

    Dictionary<string, int[]> dicSzph;
    /// <summary>
    /// 市值排行，数组第一个是行业板块市值排行，第二个是总市值排行
    /// </summary>
    public Dictionary<string, int[]> DicSzph
    {
        get
        {
            if (dicSzph != null)
            {
                return dicSzph;
            }
            string key = "CommonBLL.DicSzph";
            dicSzph = (Dictionary<string, int[]>)System.Web.HttpContext.Current.Cache[key];
            if (dicSzph != null)
            {
                return dicSzph;
            }
            string str = MemcachedTools.GetHangqingStr("EMONEY_DATA_1.0_TOP_GOODS_SHSZA_DOWN");
            List<StockPrice> lst = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StockPrice>>(str);
            dicSzph = new Dictionary<string, int[]>();
            lst = lst.OrderByDescending(x => x.SZ).ToList();
            for (int i = 0; i < lst.Count; i++)
            {
                var c = lst[i];
                try
                {
                    int[] ph = new int[2];
                    ph[1] = i + 1;
                    dicSzph.Add(c.C, ph);
                }
                catch
                {
                }
            }
            foreach (var c in DicType.Keys)
            {
                if (c.StartsWith("002"))
                {
                    string[] stocks = LstStockType.Where(x => x.BK_CODE == c).Select(x => x.GG_CODE).ToArray();
                    var tt = lst.Where(x => stocks.Contains(x.C)).OrderByDescending(x => x.SZ).ToList();
                    for (int i = 0; i < tt.Count; i++)
                    {
                        var temp = tt[i];
                        var arr = dicSzph[temp.C];
                        arr[0] = i + 1;
                        dicSzph[temp.C] = arr;
                    }
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dicSzph, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dicSzph;
        }
    }

    static List<string[]> lstCWB = null;
    public static List<string[]> LstCWB
    {
        get
        {
            if (lstCWB != null)
            {
                return lstCWB;
            }
            lstCWB = new List<string[]>();
            string[] strs = new string[3];
            strs[0] = "5";
            strs[1] = "严格控制仓位，等待机会";
            strs[2] = "耐心等待";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "15";
            strs[1] = "严格控制仓位，等待机会";
            strs[2] = "关注机会";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "25";
            strs[1] = "谨慎小心，控制仓位";
            strs[2] = "注意风险";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "40";
            strs[1] = "谨慎小心，控制仓位";
            strs[2] = "谨慎做多";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "55";
            strs[1] = "趋势未改，积极持仓";
            strs[2] = "适当控制仓位";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "65";
            strs[1] = "趋势未改，积极持仓";
            strs[2] = "适当做多";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "75";
            strs[1] = "趋势未改，积极持仓";
            strs[2] = "注意风险";
            lstCWB.Add(strs);
            strs = new string[3];
            strs[0] = "90";
            strs[1] = "重仓持有待涨";
            strs[2] = "积极做多";
            lstCWB.Add(strs);
            return lstCWB;
        }
    }
    private Dictionary<string, string> dic操盘摘要;
    public Dictionary<string, string> Dic操盘摘要
    {
        get
        {
            if (dic操盘摘要 != null)
            {
                return dic操盘摘要;
            }
            string key = "CommonBLL.操盘摘要";
            dic操盘摘要 = (Dictionary<string, string>)System.Web.HttpContext.Current.Cache[key];
            if (dic操盘摘要 != null)
            {
                return dic操盘摘要;
            }
            QgqpDAL dal = new QgqpDAL();
            var lst = dal.Get操盘摘要();
            dic操盘摘要 = new Dictionary<string, string>();
            foreach (DataRow row in lst.Rows)
            {
                string bkid = row["block_id"].ToString();
                bkid = "00" + bkid.Substring(2);
                string content = row["des"].ToString();
                if (!dic操盘摘要.Keys.Contains(key))
                {
                    dic操盘摘要.Add(bkid, content);
                }
            }
            if (dic操盘摘要 != null && dic操盘摘要.Count > 0)
            {
                System.Web.HttpContext.Current.Cache.Add(key, dic操盘摘要, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            }
            return dic操盘摘要;
        }
    }

    private Dictionary<Zhishu, List<string>> dic指数相关股票;

    public Dictionary<Zhishu, List<string>> Dic指数相关股票
    {
        get
        {
            if (dic指数相关股票 != null)
            {
                return dic指数相关股票;
            }
            string key = "CommonBLL.指数相关股票";
            dic指数相关股票 = (Dictionary<Zhishu, List<string>>)System.Web.HttpContext.Current.Cache[key];
            if (dic指数相关股票 != null)
            {
                return dic指数相关股票;
            }
            CommonBLL cbll = new CommonBLL();
            string[] stocks = cbll.DicStock.Keys.ToArray();
            dic指数相关股票 = new Dictionary<Zhishu, List<string>>();
            dic指数相关股票.Add(Zhishu.沪A, new List<string>());
            dic指数相关股票.Add(Zhishu.创业板, new List<string>());
            dic指数相关股票.Add(Zhishu.沪深300, new List<string>());
            dic指数相关股票.Add(Zhishu.深A, new List<string>());
            dic指数相关股票.Add(Zhishu.中小板, new List<string>());
            for (int i = 0; i < stocks.Length; i++)
            {
                var c = stocks[i];
                if (c.StartsWith("6"))
                {
                    dic指数相关股票[Zhishu.沪A].Add(c);
                }
                if (c.StartsWith("000"))
                {
                    dic指数相关股票[Zhishu.深A].Add(c);
                }
                if (LstStockType.Any(x => x.BK_CODE == "001009" && x.GG_CODE == c))
                {
                    dic指数相关股票[Zhishu.沪深300].Add(c);
                }
                if (c.StartsWith("002"))
                {
                    dic指数相关股票[Zhishu.中小板].Add(c);
                }
                if (c.StartsWith("300"))
                {
                    dic指数相关股票[Zhishu.创业板].Add(c);
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic指数相关股票, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic指数相关股票;
        }

    }

    private Dictionary<string, StockScore> dic千股千评;

    public Dictionary<string, StockScore> Dic千股千评
    {
        get
        {
            if (dic千股千评 != null)
            {
                return dic千股千评;
            }
            string key = "CommonBLL.Dic千股千评";
            dic千股千评 = (Dictionary<string, StockScore>)System.Web.HttpContext.Current.Cache[key];
            if (dic千股千评 != null && dic千股千评.Count>0)
            {
                return dic千股千评;
            }
            QgqpDAL dal = new QgqpDAL();
            List<StockScore> lst = dal.GetAllStockScore();
            dic千股千评 = new Dictionary<string, StockScore>();
            for (int i = 0; i < lst.Count; i++)
            {
                try
                {
                    string stockid = lst[i].StockId;
                    if (lst[i].StockId.Length == 7)
                    {
                        stockid = stockid.Substring(1);
                    }
                    dic千股千评.Add(stockid, lst[i]);
                }
                catch
                {
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic千股千评, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic千股千评;
        }
    }

    private Dictionary<string, StockScore> dic股票医生;

    public Dictionary<string, StockScore> Dic股票医生
    {
        get
        {
            if (dic股票医生 != null)
            {
                return dic股票医生;
            }
            string key = "CommonBLL.Dic股票医生";
            dic股票医生 = (Dictionary<string, StockScore>)System.Web.HttpContext.Current.Cache[key];
            if (dic股票医生 != null)
            {
                return dic股票医生;
            }
            dic股票医生 = new Dictionary<string, StockScore>();
            QgqpDAL dal = new QgqpDAL();
            List<StockScore> lst = dal.GetAllStockScore();
            for (int i = 0; i < lst.Count; i++)
            {
                try
                {
                    dic股票医生.Add(lst[i].StockId, lst[i]);
                }
                catch
                {
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic股票医生, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic股票医生;
        }
    }

    private Dictionary<string, string> dic第一财经一句话股评;

    public Dictionary<string, string> Dic第一财经一句话股评
    {
        get
        {
            if (dic第一财经一句话股评 != null && dic第一财经一句话股评.Count>0)
            {
                return dic第一财经一句话股评;
            }
            string key = "CommonBLL.Dic第一财经一句话股评";
            dic第一财经一句话股评 = (Dictionary<string, string>)System.Web.HttpContext.Current.Cache[key];
            if (dic第一财经一句话股评 != null)
            {
                return dic第一财经一句话股评;
            }

            dic第一财经一句话股评 = new Dictionary<string, string>();

            MainQuoteDBEntities dal = new MainQuoteDBEntities();

            var tempLst = dal.TB_GGFX.OrderByDescending(x => x.G_DATETIME).Take(3000).ToArray();
            foreach (var c in tempLst)
            {
                if (tempLst.Length > 0)
                {
                    try
                    {
                        if (!dic第一财经一句话股评.Keys.Contains(c.G_CODE))
                        {
                            string content = c.G_GGFX;
                            content = content.Replace("\"", "");
                            dic第一财经一句话股评.Add(c.G_CODE, content);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic第一财经一句话股评, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic第一财经一句话股评;
        }
    }

    Dictionary<string, BKTrend> dic板块自动点评;

    public Dictionary<string, BKTrend> Dic板块自动点评
    {
        get
        {
            if (dic板块自动点评 != null)
            {
                return dic板块自动点评;
            }
            string key = "CommonBLL.Dic板块自动点评";
            dic板块自动点评 = (Dictionary<string, BKTrend>)System.Web.HttpContext.Current.Cache[key];
            if (dic板块自动点评 != null)
            {
                return dic板块自动点评;
            }
            QgqpDAL dal = new QgqpDAL();
            var lst= dal.GetTrend();
            dic板块自动点评 = new Dictionary<string, BKTrend>();
            try
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    dic板块自动点评.Add("00"+lst[i].block_id.Substring(2), lst[i]);
                }
            }
            catch
            {
            }
            if (dic板块自动点评 != null)
            {
                System.Web.HttpContext.Current.Cache.Add(key, dic板块自动点评, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            }
            return dic板块自动点评;
        }
    }

    public static string 交易日期
    {
        get
        {
            string key = "CommonBLL.Get交易日期";
            string str = (string)MemcachedTools.Get(key);
            if (!string.IsNullOrEmpty(str))
            {
                return str;
            }
            HangQingBLL hbll = new HangQingBLL();
            string[] stocks = new string[] { "000001"};
            var lst= hbll.Get指数(stocks);
            string date= lst[0].T.ToString().Substring(0, 8);
            MemcachedTools.Add(key, date, DateTime.Now.AddMinutes(5));
            return date;
        }
    }

    public enum Zhishu
    {
        沪A,
        深A,
        沪深300,
        中小板,
        创业板
    }

    public string Get股票当天公告信息(DateTime date)
    {
            string key = "CommonBLL.Get股票当天交易信息_"+date.ToString("yyyyMMdd");
            string str = (string)System.Web.HttpContext.Current.Cache[key];
            if (!string.IsNullOrEmpty(str))
            {
                return str;
            }
            var stockNoticeLst=new List<StockNotice>();
            StockNoticeDAL dal = new StockNoticeDAL(); 

            stockNoticeLst= dal.GetStockNoticeByDate(date.Date);
            if (stockNoticeLst.Count > 0)
            {
                str = JsonBLL.ToJson(stockNoticeLst);
                System.Web.HttpContext.Current.Cache.Add(key, str, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, Get股票当天公告信息);
            }
            return str;
    }

    void Get股票当天公告信息(string key, object obj, System.Web.Caching.CacheItemRemovedReason c)
    {
       var  stockNoticeLst = new List<StockNotice>();
        StockNoticeDAL dal = new StockNoticeDAL();
        stockNoticeLst = dal.GetStockNoticeByDate(DateTime.Now.Date);
        if (stockNoticeLst.Count > 0)
        {
            string str = JsonBLL.ToJson(stockNoticeLst);
            System.Web.HttpContext.Current.Cache.Add(key, str, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, Get股票当天公告信息);
        }
    }

    public List<TempStock> Get证券列表()
    {
            string key = "CommonBLL_Get证券列表";
            List<TempStock> lst = (List<TempStock>)System.Web.HttpContext.Current.Cache[key];
            if(lst!=null && lst.Count>0)
            {
                return lst;
            }
            CommonBLL cbll = new CommonBLL();
            lst = new List<TempStock>();
            var dic = cbll.DicStock;
            HangQingBLL hBll = new HangQingBLL();
            string[] keys = new string[dic.Keys.Count];
            int i = 0;
            foreach (var c in dic.Keys)
            {
                keys[i] = c;
                i++;
            }
            var stockPriceLst = hBll.GetStockPrice(keys).ToList();
            System.Collections.Generic.Dictionary<string, StockPrice> dicState = new System.Collections.Generic.Dictionary<string, StockPrice>();
            foreach (var c in stockPriceLst)
            {
                try
                {
                    dicState.Add(c.C, c);
                }
                catch
                {
                }
            }
            foreach (var c in dic.Keys)
            {
                if (c.StartsWith("0") || c.StartsWith("3") || c.StartsWith("6"))
                {
                    int s = 0;
                    if (dicState.ContainsKey(c))
                    {
                        s = dicState[c].flag;
                    }
                    //C 股票代码  N 股票名称 F 类型编号 T 类型 S 股票状态
                    lst.Add(new TempStock { C = c, N = dic[c], F = "1", T = "A股", S = s });
                }
            }
            foreach (var c in cbll.DicType.Keys)
            {
                if (c.StartsWith("002"))
                {
                    lst.Add(new TempStock { C = c, N = cbll.DicType[c].BK_NAME, F = "2", T = "行业板块", S = 0 });
                }
            }
            lst.Add(new TempStock { C = "000002", N = "A股指数", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "000001", N = "上证指数", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "399001", N = "深证成指", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "000300", N = "沪深300", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "399005", N = "中小板指数", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "399006", N = "创业板指数", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "001006", N = "上证50", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "000903", N = "中证100", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "000010", N = "上证180", F = "3", T = "指数", S = 0 });
            lst.Add(new TempStock { C = "001027", N = "深证100", F = "3", T = "指数", S = 0 });
            System.Web.HttpContext.Current.Cache.Add(key, lst, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return lst;
    }

    public Dictionary<string, TempStock> Dic证券列表
    {
        get
        {
            string key = "CommonBLL_Dic证券列表";
            Dictionary<string, TempStock> dic = (Dictionary<string, TempStock>)System.Web.HttpContext.Current.Cache[key];
            if (dic != null && dic.Count > 0)
            {
                return dic;
            }
            var lst = Get证券列表();
            dic = new Dictionary<string, TempStock>();
            for (int i = 0; i < lst.Count; i++)
            {
                var c=lst[i];
                if (c.C.Length == 6)
                {
                    if (!dic.ContainsKey(c.C))
                    {
                        dic.Add(c.C, c);
                    }
                    if (!dic.ContainsKey(c.N))
                    {
                        dic.Add(c.N, c);
                    }
                }
            }
            System.Web.HttpContext.Current.Cache.Add(key, dic, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);
            return dic; ;
        }
    }
}